﻿using System.IO;

namespace Rename.UC.FastOLSV
{
    public class UcFastOlsv文件夹重命名:UcFastOlsvBase
    {
        private BrightIdeasSoftware.OLVColumn 原文件夹名 = new BrightIdeasSoftware.OLVColumn();
        private BrightIdeasSoftware.OLVColumn 新文件夹名 = new BrightIdeasSoftware.OLVColumn();
        private BrightIdeasSoftware.OLVColumn 文件夹路径 = new BrightIdeasSoftware.OLVColumn();
        private BrightIdeasSoftware.OLVColumn 创建时间 = new BrightIdeasSoftware.OLVColumn();
        private BrightIdeasSoftware.OLVColumn 文件数 = new BrightIdeasSoftware.OLVColumn();
        private BrightIdeasSoftware.OLVColumn 文件夹数 = new BrightIdeasSoftware.OLVColumn();
        private BrightIdeasSoftware.OLVColumn 大小 = new BrightIdeasSoftware.OLVColumn();
        private BrightIdeasSoftware.OLVColumn 状态 = new BrightIdeasSoftware.OLVColumn();
        public UcFastOlsv文件夹重命名()
        {

        }

        protected override LsvFileBase AddRow(string file, string rule)
        {
            LsvFile文件夹重命名 file_info = new LsvFile文件夹重命名();

            file_info.FileName = Path.GetFileName(file);
            file_info.Path = Path.GetDirectoryName(file);

            file_info.NewFileName = Path.GetFileName(file);
            DirectoryInfo dirInfo = new DirectoryInfo(file);
            file_info.Size = Util.FormatFileSize(Rename.Util.DirHelper.GetDirectorySize(dirInfo));
            file_info.CrTime = dirInfo.CreationTime.ToString(DATE_FORMATE);

            int totalFiles = 0;
            int totalDirectories = 0;
            Rename.Util.DirHelper.CountFilesAndDirectories(dirInfo, ref totalFiles, ref totalDirectories);

            file_info.FileCount = totalFiles; //$"{totalFiles} 个文件, {totalDirectories} 个文件夹";
            file_info.DirCount=totalDirectories;
            return file_info;
        }
        protected override object GetFileIcon(object row)
        {
            return sImgList.Images.IndexOfKey("folder");
        }

        protected override void SetupColumns()
        {
            fastOlsv.AllColumns.Add(this.原文件夹名);
            this.原文件夹名.AspectName = "FileName";
            this.原文件夹名.IsEditable = false;
            this.原文件夹名.Text = "原文件夹名";
            this.原文件夹名.Width = 150;
            this.原文件夹名.ImageGetter = GetFileIcon;

            fastOlsv.AllColumns.Add(this.新文件夹名);
            this.新文件夹名.AspectName = "NewFileName";
            this.新文件夹名.Text = "新文件夹名";
            this.新文件夹名.Width = 150;

            fastOlsv.AllColumns.Add(this.文件夹路径);
            this.文件夹路径.AspectName = "Path";
            this.文件夹路径.IsEditable = false;
            this.文件夹路径.Text = "文件夹路径";
            this.文件夹路径.Width = 300;

            fastOlsv.AllColumns.Add(this.创建时间);
            this.创建时间.AspectName = "CrTime";
            this.创建时间.IsEditable = false;
            this.创建时间.Text = "创建时间";
            this.创建时间.Width = 175;

            fastOlsv.AllColumns.Add(this.大小);
            this.大小.AspectName = "Size";
            this.大小.IsEditable = false;
            this.大小.Text = "大小";
            this.大小.Width = 90;

            fastOlsv.AllColumns.Add(this.文件数);
            this.文件数.AspectName = "FileCount";
            this.文件数.IsEditable = false;
            this.文件数.Text = "文件数";
            this.文件数.Width = 80;

            fastOlsv.AllColumns.Add(this.文件夹数);
            this.文件夹数.AspectName = "FileCount";
            this.文件夹数.IsEditable = false;
            this.文件夹数.Text = "文件夹数";
            this.文件夹数.Width = 80;

            fastOlsv.AllColumns.Add(this.状态);
            this.状态.AspectName = "Status";
            this.状态.IsEditable = false;
            this.状态.Text = "状态";
            this.状态.Width = 80;

            base.SetupColumns();
            fastOlsv.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { 原文件夹名, 新文件夹名, 文件夹路径, 创建时间,大小, 文件数,文件夹数, 状态, 操作 });
        }
    }
}
